/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation
**
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
**   * Redistributions of source code must retain the above copyright
**     notice, this list of conditions and the following disclaimer.
**   * Redistributions in binary form must reproduce the above copyright
**     notice, this list of conditions and the following disclaimer in
**     the documentation and/or other materials provided with the
**     distribution.
**   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
**     the names of its contributors may be used to endorse or promote
**     products derived from this software without specific prior written
**     permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
** $QT_END_LICENSE$
** Description:
****************************************************************************/
import QtQuick 1.0
import com.nokia.symbian 1.0


ApplicationWindow {
    id: window

    function setStateIfFound(target, name) {
        for (var i = 0; i < target.states.length; i++) {
            var curState = target.states[i];
            if(curState.name == name) {
                target.state = name
                break
            }
        }
    }







    ToolBarLayout {
        id: commonTools
        ToolButton {
            flat: true
            iconSource: "qrc:/qtg_toolbar_back.svg"
            onClicked: pageStack.depth <= 1 ? Qt.quit() : pageStack.pop()
        }
        ToolButton {
            flat: true
            iconSource: "qrc:/qtg_toolbar_options.svg"
            onClicked:
            {
                viewMenu.open()
            }
        }
    }

    Page {
        id: page
        anchors.fill: parent
        tools: commonTools

        Component.onCompleted: {
            if(screen.currentOrientation == Screen.Portrait) {
                setStateIfFound(page, "PortraitState")
            } else if(screen.currentOrientation == Screen.Landscape) {
                setStateIfFound(page, "LandscapeState")
            }
        }

        //Image that contains the display image on the mainRect.
        Image {
            id: imagePoster
            y:window.TopLeft
            x:window.TopLeft
            height: window.height
            width:  window.width
            source: "qrc:/rectbackground.jpg"

            }

        // Text to display the application name.
        PageHeading{
            id: heading
            anchors.top: parent.top
            width: parent.width
            text: "Light API Example"
            fontItalic: true
        }

        //Text to display the status of the primary display.
        Text {
                id:displayStatus
                text: "Display Status = On"
                font.family: "Helvetica"
                font.pointSize: 10
                color: "grey"
                font.italic :true
                width: 100
                height: 40
                y:(window.height/2- 100)
                anchors.rightMargin: parent.right
               }
        // Text to display the button pressed.
        Text {
                id:menuPress
                text: ""
                font.family: "Helvetica"
                font.pointSize: 10
                color: "grey"
                font.italic :true
                width: 100
                height: 40
                y:(window.height/2)
                anchors.rightMargin: parent.right
               }

            Menu{
                id: viewMenu

                    content:
                    Column{
                    MenuItem {
                        text: "Maximum"

                        onClicked:
                        {
                            menuPress.text = "Display at Max intensity \nfor 8 Sec"
                            lightWrapper.lightOn();
                            lightWrapper.lightMax();
                            viewMenu.close()
                        }
                    }
                    MenuItem { text: "Minimum"
                        onClicked:
                        {
                            menuPress.text = "Display at Min intensity \nfor 8 Sec"
                            lightWrapper.lightOn();
                            lightWrapper.lightMin();
                            viewMenu.close()
                        }
                    }
                    MenuItem { text: "Blink"
                        onClicked:
                        {
                            menuPress.text = "Display blinking for 8 Sec"
                            lightWrapper.lightOn();
                            lightWrapper.lightBlink();
                            viewMenu.close()
                        }
                    }
                    MenuItem { text: "Off"
                        onClicked:
                        {
                            menuPress.text = "Display off for 8 Sec"
                            lightWrapper.lightOn();
                            lightWrapper.lightOff();
                            viewMenu.close()
                        }
                    }
                }

            }

    }
    Component.onCompleted: pageStack.push(page)

    //Connections to attach the QT signal to QML slot.
    Connections {
           target: lightWrapper
           onPrintStatus: {
               displayStatus.text = "Display Status = "+status
       }
    }


}
